package com.pn.controller;

import com.pn.entity.OutStore;
import com.pn.entity.Result;
import com.pn.service.OutStoreService;
import com.pn.utils.CurrentUser;
import com.pn.utils.TokenUtils;
import com.pn.utils.WarehouseConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/outstore")
@RestController
public class OutStoreController {
    @Autowired
    private OutStoreService outStoreService;
    @Autowired
    private TokenUtils tokenUtils;

    @RequestMapping("/outstore-add")
    public Result addOutStore(@RequestBody OutStore outStore,
                              @RequestHeader(
                                      WarehouseConstants.HEADER_TOKEN_NAME
                              ) String token) {
//        拿到用户token 里包含ID
        CurrentUser currentUser = tokenUtils.getCurrentUser(token);
//        取出ID
        int createBy = currentUser.getUserId();
//       把用户ID存进出库表
        outStore.setCreateBy(createBy);
//        把出库信息传回 业务层处理
        return outStoreService.saveOutStore(outStore);

    }
}
